package com.example.jqying.androiddemo.popupWindow;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import com.example.jqying.androiddemo.R;

public class PopupWindowActivity extends AppCompatActivity {


    private PopupWindow mPopWin;
    private Button mBtnPop;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_popup_window);
        mBtnPop = (Button) findViewById(R.id.btn_popWin);
        mBtnPop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                View view1 = getLayoutInflater().inflate(R.layout.layout_popup_window,null);
                TextView textView = (TextView) view1.findViewById(R.id.tv_ok);
                textView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        mPopWin.dismiss();
                        //to do
                        Toast.makeText(PopupWindowActivity.this,"OK",Toast.LENGTH_SHORT).show();
                    }
                });


                mPopWin = new PopupWindow(view1,mBtnPop.getWidth(), ViewGroup.LayoutParams.WRAP_CONTENT);
                mPopWin.setOutsideTouchable(true);
                mPopWin.showAsDropDown(mBtnPop);
            }
        });

    }
}
